//declarar variables del funcionamiento de la LCD
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
 unsigned   DATO_RECIBIDO;    // dimension del variable donde se almacenara lo que lea del puerto serial
 char txt1[] = "DATO RECIBIDO:";
 char txt2[8];

void main() {
portd=0;
trisd= 0;     //puerto D como salida

//delay_ms(500);
portd=0;
Lcd_Init();                               // Inicializo la LCD
  Lcd_Cmd(_LCD_CLEAR);                    // borro la LCD
  Lcd_Cmd(_LCD_CURSOR_OFF);               // apago cursor
  Lcd_Out(1,1, txt1);                     //escribo DATO RECIBIDO
//inicio de la comunicacion serial
UART1_Init(9600);                         // Inicializo la UART  9600 bps
  Delay_ms(100);                          //tiempo de la estabilizacion
  while (1) {                             // ciclo de lectura de datos
    if (UART1_Data_Ready()) {             // si  hay datos en el buffer del pic
      DATO_RECIBIDO = UART1_Read();       // los leeo y los guardo en la variable DATO_RECIBIDO

      }
      switch (DATO_RECIBIDO){
      case 49: portd=60;  break;          //evaluo si el DATO_RECIBIDO es igual a 65 y si es true ejecuto portd=60
      case 50: portd=125; break;          //evaluo si el DATO_RECIBIDO es igual a 66 y si es true ejecuto portd=125
      case 51: portd=255; break;          //evaluo si el DATO_RECIBIDO es igual a 67 y si es true ejecuto portd=255
      }
      
      wordToStr(DATO_RECIBIDO, txt2);      //convierto a string los datos recibidos para mostrarlo en la LCD
      Lcd_Out(2,3,txt2);

      }
}